import Vue from 'vue';
import Vuex from 'vuex';
import * as types from './mutation-types';
import vuexAlong from "vuex-along";//数据持久化

Vue.use(Vuex);
export default new Vuex.Store({
    state: {
        count: 0,
    },
    getters: {},
    //同步
    mutations: {
        [types.SOME_MUTATION] (state, payload) {
            state.count += payload || 1;
        }
    },
    //异步
    actions: {
        increment (context, param) {
            context.state.count += param;
            setTimeout(() => { //模拟异步
                context.commit(types.SOME_MUTATION, context.state.count)
            }, 1000)

        }
    },
    plugins: [vuexAlong()],
})